﻿#include "TurnTableDecode_TurnTable_Error.h"

#include "TurnTableCodec.h"
#include "TcpCodec.h"

TurnTableDecode_TurnTable_Error::TurnTableDecode_TurnTable_Error(TurnTableCodec *turnTableCodec)
{
  this->turnTableCodec=turnTableCodec;
}

TurnTableDecode_TurnTable_Error::~TurnTableDecode_TurnTable_Error()
{

}

void TurnTableDecode_TurnTable_Error::decode(char* const data,uint deviceId)
{
  uchar errorType=*(data+3);
  logSaver->saveLog(QStringLiteral("TurnTableCodec,error:%1").arg(errorType),LogSaver::Critical);
  emit turnTableCodec->signal_turnTableError((TurnTableCodec::ErrorFlag)errorType,deviceId);
  bool isOk=false;
  uint userId=turnTableCodec->getLastUserIdByDeviceId(deviceId,&isOk);
  if(isOk)
    {
      turnTableCodec->getTcpCodec()->code(userId,
                                          TcpCodec::TurnTable,
                                          QByteArray().append((uchar)TurnTableCodec::TurnTable_Error)
                                                      .append(errorType));
    }
}
